package com.smartkey.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;

public class ScreenRotationUtils {

	/**
	 * 得到屏幕旋转的状态
	 * 
	 * @param context
	 * @return
	 */
	public static int getRotationStatus(Context context) {
		int status = 0;
		try {
			status = android.provider.Settings.System.getInt(
					context.getContentResolver(),
					android.provider.Settings.System.ACCELEROMETER_ROTATION);
		} catch (SettingNotFoundException e) {
			e.printStackTrace();
		}
		return status;
	}

	/**
	 * 改变屏幕方向
	 * 
	 * @param context
	 */
	public static void changeRotationStatus(Context context) {
//		ContentResolver resolver = context.getContentResolver();
//		int status = getRotationStatus(context);
//		// 得到uri
//		Uri uri = android.provider.Settings.System
//				.getUriFor("accelerometer_rotation");
//		// 沟通设置status的值改变屏幕旋转设置
//		android.provider.Settings.System.putInt(resolver,
//				"accelerometer_rotation", status);
//		// 通知改变
//		resolver.notifyChange(uri, null);
		
		//得到是否开启
		int flag = Settings.System.getInt(context.getContentResolver(),
				Settings.System.ACCELEROMETER_ROTATION, 0);
		int isOpen = flag==1?0:1;
		Settings.System.putInt(context.getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, isOpen);

	}

}
